<?php


namespace app\controller\admin;


use app\model\AdminFeedbackRecord;
use think\Response;

class FeedbackRecord extends Base
{
    /**
     * 获取反馈列表
     * @return Response
     * @throws \think\db\exception\DbException
     */
    public function index(): Response {
        $limit = $this->request->get('size', config('apiadmin.ADMIN_LIST_DEFAULT'));
        $start = $this->request->get('page', 1);
        $problem_type = $this->request->get('problem_type', '');
        $dateScope = $this->request->get('scope', []);

        $obj = new AdminFeedbackRecord();
        if ($problem_type) {
            $obj->where('problem_type', $problem_type);
        }
        if (!empty($dateScope) && array_filter($dateScope)) {
            $obj->whereTime('create_time', 'between', $dateScope);
        }
        $listObj = $obj->order('create_time', 'DESC')
            ->paginate(['page' => $start, 'list_rows' => $limit])->toArray();

        return $this->buildSuccess([
            'list'  => $listObj['data'],
            'count' => $listObj['total'],
            'type_list' => AdminFeedbackRecord::getTypeList()
        ]);
    }
}